let tableUtils = {
    exist(num){
        return num >= 0;
    }
    ,notExist(sNum,eNum){
        //起始位置不存在或起始位置大于结束位置，则认为不存在的
        return !(sNum >= 0) || sNum > eNum;
    }
    /**
     * @param {table dom el } table:表格dom元素
     * @param {Number}row:行索引,索引从0开始
     * @param {Number}col:列索引,索引从0开始
     * @param {Number}startRow:开始行索引,索引从0开始
     * @param {Number}endRow:结束行索引,索引从0开始
     * @param {Number}startCol:结束列索引,索引从0开始
     * @param {Number}endCol:结束列索引,索引从0开始
     * @param {Number}count:合并数
     */

    ,getTrByRow(table,row){
        return table.rows[row];
    }

    ,getColsByRow(table,row){
        return table.rows[row];
    }

    ,setColSpan(table,row,col,val){
        table.rows[row].cells[col].colSpan = val;
    }

    ,setRowSpan(table,row,col){
        table.rows[row].cells[col].rowSpan = val;
    }

    //根据行删除单元格(列)
    ,delColByRow(table,row,startCol,endCol){
        let tr = table.rows[row];
        !endCol && (endCol = tr.cells.length-1)
        while(endCol >= startCol){
            tr.deleteCell(endCol)
            endCol--;
        }
    }

    //根据列索引，合并指定行
    ,mergeRowByCol(table,col,startRow,endRow){
        !endRow && (endRow = table.rows.length-1);
        for(let i = startRow; i < endRow; i++) {
            let row = table.rows[i+1];
            row.deleteCell(col); 
            table.rows[startRow].cells[col].rowSpan = table.rows[startRow].cells[col].rowSpan+1;
        }
    }

    //根据合并数,对表格行合并
    ,mergeRowByCount(table,col,startRow,count){
        this.notExist(count,table.rows.length-1) && (count = table.rows.length-1);
        let cell = table.rows[startRow].cells[col];
        let endRow = startRow + count;
        for(let i = startRow; i < endRow; i++) {
            let row = table.rows[i+1];
            row.deleteCell(col); 
            cell.rowSpan = table.rows[startRow].cells[col].rowSpan+1;
        }
    }

    //根据行索引，对表格列合并
    ,mergeColByRow(table,row,startCol,endCol){
        let tr = table.rows[row]
        !endCol && (endCol = tr.cells.length-1);
        for(let i = endCol; i > startCol; i--){
            tr.deleteCell(i); 
            tr.cells[startCol].colSpan = table.rows[row].cells[startCol].colSpan+1;
        }
    }

    //根据合并数，对表格进行列合并
    ,mergeColByCount(table,row,startCol,count){
        let tr = table.rows[row];
        this.notExist(count,tr.cells.length-1) && (count = tr.cells.length-1);
        let endCol = startCol + count;
        for(let i = endCol; i > startCol; i--){
            tr.deleteCell(i); 
            tr.cells[startCol].colSpan = table.rows[row].cells[startCol].colSpan+1;
        }
    }

    //获取所有列或指定列的所有单元格
    ,getCells(table,startCol,endCol,startRow,endRow){
        let cols = [];
        this.notExist(startCol) && (startCol = 0)     
        this.notExist(endCol) && (endCol = table.rows[table.rows.length-1].cells.length)
        this.notExist(startRow) && (startRow = 0)
        this.notExist(endRow) && (endRow = table.rows.length)
        for(let i = startCol; i < endCol; i++){
            let col = {};
            for(let j = startRow; j < endRow; j++){
                col[j] = table.rows[j].cells[i];
            }
            cols.push(col);
            col.length = Object.keys(col).length;
        }    
        return cols;
    }

    //根据相同内容，对表格进行，行合并
    ,mergeRowByContent(table,startRow){
        let cols = this.getCells(table,-1,-1,startRow);
        this.notExist(startRow) && (startRow = 0)
        for(let i = 0; i < cols.length; i++){
            let col = cols[i];
            for(let j = startRow; j < col.length; j++){
                let td = col[j];
                for(let k = j+1; k < col.length; k++){
                    let nextTd = col[k];
                    if(nextTd.textContent == td.textContent){
                        td.rowSpan = td.rowSpan+1;
                        table.rows[k].deleteCell(i);
                        delete col[k];
                        j++;
                    }
                }
            }
            // let row = table.rows[i+1];
            // row.deleteCell(col); 
            // cell.rowSpan = table.rows[startRow].cells[col].rowSpan+1;
        }
        
    }
    



}